package com.xinqi.modules.chat.chat.chat.controller.web;

import com.xinqi.common.base.response.R;
import com.xinqi.common.core.utils.MessageUtils;
import com.xinqi.common.satoken.utils.LoginHelper;
import com.xinqi.modules.chat.chat.chat.dto.req.ChatNoticeCreateDTO;
import com.xinqi.modules.chat.chat.chat.dto.rsp.ChatNoticeResultDTO;
import com.xinqi.modules.chat.chat.chat.service.ChatNoticeService;
import com.xinqi.modules.chat.chat.group.dto.rsp.ChatGroupUserResultDTO;
import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * WEB -- 群公告记录
 *
 * @version V1.0
 * @Title:
 * @ClassName: com.xinqi.modules.chat.chat.chat.controller.web.ChatNoticeWebController.java
 * @Description:
 * @Copyright 星齐科技（云南）有限公司 - Powered By 技术部
 * @author: yyzhen
 * @date: 2023/5/19 9:08
 */
@Validated
@RestController
@RequestMapping("/web/chat-notice")
@RequiredArgsConstructor
public class ChatNoticeWebController {
    private final ChatNoticeService chatNoticeService;

    @Operation(summary = "群公告设置-(群主管理)")
    @PostMapping("/{groupId}")
    public R<Boolean> setGroupNotice(@Validated @RequestBody ChatNoticeCreateDTO dto) {
        return R.data(chatNoticeService.setGroupNotice(dto, LoginHelper.getXqLoginUser()), MessageUtils.message("chat.chat.notice.message.success"));
    }

    @Operation(summary = "群公告查询")
    @GetMapping("/{groupId}/get-detail")
    public R<ChatNoticeResultDTO> getGroupNoticeDetail(@NotEmpty(message = "{chat.chat.groupId.not.blank}") @PathVariable("groupId") String groupId) {
        return R.data(chatNoticeService.getGroupNoticeDetail(LoginHelper.getUserId(), groupId));
    }

    @Operation(summary = "群公告-阅读")
    @PutMapping("/set-read/{id}")
    public R<Boolean> setNoticeRead(@NotNull(message = "{chat.chat.notice.id.not.blank}") @PathVariable("id") Long id) {
        return R.data(chatNoticeService.setNoticeRead(LoginHelper.getUserId(), id));
    }

    @Operation(summary = "群公告-阅读成员列表")
    @GetMapping("/read/{id}")
    public R<Map<String, List<ChatGroupUserResultDTO>>> getNoticeReadUsers(@NotNull(message = "{chat.chat.notice.id.not.blank}") @PathVariable("id") Long id) {
        return R.data(chatNoticeService.getNoticeReadUsers(id));
    }
}
